package com.by.controller;

import cn.hutool.core.bean.BeanUtil;
import com.by.bean.FreighthEnquiry;
import com.by.common.bean.PageBean;
import com.by.common.bean.ResultBean;
import com.by.common.controller.BaseController;
import com.by.query.FreightCleintQuery;
import com.by.query.FreightQuery;
import com.by.service.FreighthEnquiryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author Ye QS
 * @version 0.1
 * @className FreighthController
 * @description
 * @date 2024/9/29 15:40
 * @since jdk11
 */
@RestController
@Api(tags = "货代询价")
@RequestMapping("/v1")
public class FreighthController extends BaseController {
    @Autowired
    FreighthEnquiryService freighthEnquiryService;

    @ApiOperation("保存询价")
    @PostMapping("/freighthEnquiry")
    public ResultBean save(@RequestBody FreighthEnquiry freighthEnquiry) {
        int rs = freighthEnquiryService.save(freighthEnquiry);
        return saveResult(rs);
    }

    @ApiOperation("货代管理")
    @PostMapping("/freighthEnquiry/query")
    public ResultBean query(@RequestBody FreightQuery freightQuery) {
        Map<String, Object> map = BeanUtil.beanToMap(freightQuery);
        PageBean query = freighthEnquiryService.query(map);
        return success("货代列表", query);
    }

    @ApiOperation("货代列表")
    @PostMapping("/freighthEnquiry/list")
    public ResultBean queryFreighth(@RequestBody FreightCleintQuery query) {
        PageBean pageBean = freighthEnquiryService.queryFreighth(query);
        return success("货代列表", pageBean);
    }
}
